<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=9">
<meta name="generator" content="Doxygen 1.8.13">
<title>OpenCV:在Linux中的安装</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon">
<link href="../../tabs.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css">
<link href="../../stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../df/d65/tutorial_table_of_content_introduction.html">Introduction to OpenCV</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Installation in Linux(在Linux中安装)</div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>目录</h3>
<ul><li class="level1"><a href="#tutorial_linux_install_quick_start">快速启动</a><ul><li class="level2"><a href="#tutorial_linux_install_quick_build_core">Build core modules(构建核心模块)</a></li>
<li class="level2"><a href="#tutorial_linux_install_quick_build_contrib">构建opencv_contrib</a></li>
</ul>
</li>
<li class="level1"><a href="#tutorial_linux_install_detailed">详细流程</a><ul><li class="level2"><a href="#tutorial_linux_install_detailed_basic_compiler">安装编译器和生成工具</a></li>
<li class="level2"><a href="#tutorial_linux_install_detailed_basic_download">下载源码</a></li>
<li class="level2"><a href="#tutorial_linux_install_detailed_basic_build">配置和生成</a></li>
<li class="level2"><a href="#tutorial_linux_install_detailed_basic_verify">检查生成结果</a></li>
</ul>
</li>
</ul>
</div>
<div class="textblock"><p><b>下一个教程:</b> <a class="el" href="../../db/df5/tutorial_linux_gcc_cmake.html">Using OpenCV with gcc and CMake</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">原作者</td><td align="left">Ana Huamán</td></tr>
<tr>
<td align="right">兼容性</td><td align="left">OpenCV &gt;= 3.0</td></tr>
</table>
<h1><a class="anchor" id="tutorial_linux_install_quick_start"></a>快速启动</h1>
<h2><a class="anchor" id="tutorial_linux_install_quick_build_core"></a>构建核心模块</h2>
<div class="fragment"><div class="line"># Install minimal prerequisites (Ubuntu 18.04 as reference)</div><div class="line">sudo apt update &amp;&amp; sudo apt install -y cmake g++ wget unzip</div><div class="line"></div><div class="line"># Download and unpack sources</div><div class="line">wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip</div><div class="line">unzip opencv.zip</div><div class="line"></div><div class="line"># Create build directory</div><div class="line">mkdir -p build &amp;&amp; cd build</div><div class="line"></div><div class="line"># Configure</div><div class="line">cmake  ../opencv-master</div><div class="line"></div><div class="line"># Build</div><div class="line">cmake --build .</div></div><!-- fragment --><h2><a class="anchor" id="tutorial_linux_install_quick_build_contrib"></a>构建opencv_contrib</h2>
<div class="fragment"><div class="line"># Install minimal prerequisites (Ubuntu 18.04 as reference)</div><div class="line">sudo apt update &amp;&amp; sudo apt install -y cmake g++ wget unzip</div><div class="line"></div><div class="line"># Download and unpack sources</div><div class="line">wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip</div><div class="line">wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/master.zip</div><div class="line">unzip opencv.zip</div><div class="line">unzip opencv_contrib.zip</div><div class="line"></div><div class="line"># Create build directory and switch into it</div><div class="line">mkdir -p build &amp;&amp; cd build</div><div class="line"></div><div class="line"># Configure</div><div class="line">cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules ../opencv-master</div><div class="line"></div><div class="line"># Build</div><div class="line">cmake --build .</div></div><!-- fragment --><h1><a class="anchor" id="tutorial_linux_install_detailed"></a>详细流程</h1>
<p>本节提供了构建过程的更多细节,并描述了替代方法和工具.请参阅<a class="el" href="../../d0/d3d/tutorial_general_install.html">OpenCV installation overview</a>教程的一般安装细节和<a class="el" href="../../db/d05/tutorial_config_reference.html">OpenCV configuration options reference</a>配置选项文档.</p>
<h2><a class="anchor" id="tutorial_linux_install_detailed_basic_compiler"></a>安装编译器和生成工具</h2>
<ul>
<li>要编译OpenCV,你需要一个C++编译器.通常是G++/GCC或Clang/LLVM:<ul>
<li>Install GCC...<div class="fragment"><div class="line">sudo apt install -y g++</div></div><!-- fragment --></li>
<li>... or Clang:<div class="fragment"><div class="line">sudo apt install -y clang</div></div><!-- fragment --></li>
</ul>
</li>
<li>OpenCV使用CMake构建配置工具:<div class="fragment"><div class="line">sudo apt install -y cmake</div></div><!-- fragment --></li>
<li>CMake可以为不同的构建系统生成脚本,例如.<em>make</em>,<em>ninja</em>:<ul>
<li>安装Make...<div class="fragment"><div class="line">sudo apt install -y make</div></div><!-- fragment --></li>
<li>... 或 Ninja:<div class="fragment"><div class="line">sudo apt install -y ninja-build</div></div><!-- fragment --></li>
</ul>
</li>
<li>安装获取和解包源的工具:<ul>
<li><em>wget</em>和<em>unzip</em>...<div class="fragment"><div class="line">sudo apt install -y wget unzip</div></div><!-- fragment --></li>
<li>... 或<em>git</em>:<div class="fragment"><div class="line">sudo apt install -y git</div></div><!-- fragment --></li>
</ul>
</li>
</ul>
<h2><a class="anchor" id="tutorial_linux_install_detailed_basic_download"></a>下载源</h2>
<p>获取OpenCV源代码有两种方法:</p>
<ul>
<li>使用web浏览器或任何下载工具（约80-90Mb）下载存储库的快照并将其解压缩...<div class="fragment"><div class="line">wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip</div><div class="line">unzip opencv.zip</div><div class="line">mv opencv-master opencv</div></div><!-- fragment --></li>
<li>... 或使用将存储库克隆到本地计算机<em>git</em>获取完整的更改历史记录 (&gt;470Mb):<div class="fragment"><div class="line">git clone https://github.com/opencv/opencv.git</div><div class="line">git -C opencv checkout master</div></div><!-- fragment --></li>
</ul>
<dl class="section note"><dt>Note</dt><dd>其他分支、版本或提交的快照可以在<a href="https://github.com/opencv/opencv">GitHub</a>以及<a href="https://opencv.org/releases.html">官方下载页</a>.</dd></dl>
<h2><a class="anchor" id="tutorial_linux_install_detailed_basic_build"></a>配置和生成</h2>
<ul>
<li>创建生成目录:<div class="fragment"><div class="line">mkdir -p build &amp;&amp; cd build</div></div><!-- fragment --></li>
<li>配置-为首选生成系统生成生成脚本:<ul>
<li>为了<em>make</em>...<div class="fragment"><div class="line">cmake ../opencv</div></div><!-- fragment --></li>
<li>... 或为<em>ninja</em>:<div class="fragment"><div class="line">cmake -GNinja ../opencv</div></div><!-- fragment --></li>
</ul>
</li>
<li>生成-运行实际编译过程:<ul>
<li>Using<em>make</em>...<div class="fragment"><div class="line">make -j4</div></div><!-- fragment --></li>
<li>... 或<em>ninja</em>:<div class="fragment"><div class="line">ninja</div></div><!-- fragment --></li>
</ul>
</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><em>Configure(配置)</em>进程可以从internet下载一些文件以满足库依赖关系,连接失败可能导致某些模块或功能关闭或行为不同.参考<a class="el" href="../../d0/d3d/tutorial_general_install.html">OpenCV installation overview</a>和<a class="el" href="../../db/d05/tutorial_config_reference.html">OpenCV configuration options reference</a>有关详细信息和完整配置选项参考的教程.</dd>
<dd>如果在生成过程中遇到问题,请尝试清理或重新创建生成目录.配置中的更改（如禁用依赖项、修改构建脚本或将源切换到另一个分支）处理得不是很好,可能会导致工作区中断.</dd>
<dd>
<em>Make</em>可以并行运行多个编译进程,<code>-j&lt;NUM&gt;</code>选项表示 "运行 &lt;数量&gt; 工作同时进行".<em>Ninja</em>将自动检测可用处理器内核的数量,而不需要<code>-j</code>选项.</dd></dl>
<h2><a class="anchor" id="tutorial_linux_install_detailed_basic_verify"></a>检查生成结果</h2>
<p>成功构建后,您将在<code>build/lib</code>目录和可执行文件（测试、示例、应用程序）<code>build/bin</code>目录:</p><div class="fragment"><div class="line">ls bin</div><div class="line">ls lib</div></div><!-- fragment --><p>CMake包文件将位于生成根目录中:</p><div class="fragment"><div class="line">ls OpenCVConfig*.cmake</div><div class="line">ls OpenCVModules.cmake</div></div><!-- fragment --><h2>安装</h2>
<dl class="section warning"><dt>警告</dt><dd>安装过程只会将文件复制到预定义的位置并进行小修补.使用此方法安装的库未集成到系统包注册表中,无法自动卸载.由于可能与系统包冲突,我们不建议常规用户在系统范围内安装.</dd></dl>
<p>默认情况下,OpenCV将安装到<code>/usr/local</code>目录中,所有文件将复制到以下位置:</p><ul>
<li><code>/usr/local/bin</code>- executable files</li>
<li><code>/usr/local/lib</code>- libraries (.so)</li>
<li><code>/usr/local/cmake/opencv4</code>- cmake package</li>
<li><code>/usr/local/include/opencv4</code>- headers</li>
<li><code>/usr/local/share/opencv4</code>-其他文件（如XML格式的训练级联）</li>
</ul>
<p>Since<code>/usr/local</code>属于根用户,安装应以提升的权限执行(<code>sudo</code>):</p><div class="fragment"><div class="line">sudo make install</div></div><!-- fragment --><p>或</p><div class="fragment"><div class="line">sudo ninja install</div></div><!-- fragment --><p>安装根目录可以用<code>CMAKE_INSTALL_PREFIX</code>配置参数,例如.<code>-DCMAKE_INSTALL_PREFIX=$HOME/.local</code>安装到当前用户的本地目录.安装布局可以通过<code>OPENCV_*_INSTALL_PATH</code>参数.看到了吗<a class="el" href="../../db/d05/tutorial_config_reference.html">OpenCV configuration options reference</a>详情.</p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"><address class="footer"><small>Generated on Fri Apr 2 2021 11:36:36 for OpenCV by<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen">
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
